import 'package:flutter/material.dart';

class RouteNames {
  static GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();

  static const String initialPage = '/';
  static const String splashPage = '/splashPage';
  static const String agreePrivacyPage = '/agreePrivacyPage';
  static const String homePage = '/homePage';
  static const String loginPage = '/loginPage';
  static const String playerPage = '/playerPage';
  static const String webPage = '/webPage';
  static const String historyPage = '/historyPage';
  static const String collectedPage = '/collectedPage';
  static const String deleteAccountPage = '/deleteAccountPage';
  static const String removeAdsPage = '/removeAdsPage';

  static pushNamed(String name, {dynamic arguments}) {
    return navigatorKey.currentState?.pushNamed(name, arguments: arguments);
  }

  static push(Widget widget) {
    return navigatorKey.currentState?.push(MaterialPageRoute(builder: (_) => widget));
  }

  static pushReplacement(Widget widget) {
    return navigatorKey.currentState?.pushReplacement(MaterialPageRoute(builder: (_) => widget));
  }

  static pushWithAnim(BuildContext context, Widget child) => Navigator.of(context).push(
    PageRouteBuilder(
      opaque: false,
      fullscreenDialog: true,
      transitionsBuilder: (_, Animation<double> animation, __, Widget child) => FadeTransition(opacity: animation, child: child),
      pageBuilder: (_, __, ___) => child,
    ),
  );

  static pop<T>({T? result}) {
    if (navigatorKey.currentState?.canPop() ?? false) {
      navigatorKey.currentState?.pop(result);
    }
  }

  static bool canPop() {
    return navigatorKey.currentState?.canPop() ?? false;
  }

  static openReplace(String name, {dynamic arguments}) {
    navigatorKey.currentState?.pushReplacementNamed(name, arguments: arguments);
  }

  static openAndRemovedUntil(String name) {
    navigatorKey.currentState?.pushNamedAndRemoveUntil(name, (route) => false);
  }

  static openAndRemovedUntilWidget(Widget widget) {
    navigatorKey.currentState?.pushAndRemoveUntil(
        MaterialPageRoute(builder: (_) => widget), (route) => false);
  }

  static const String SPLASH_PAGE = '/Splash';

  static final routers = {
    // SELL_HOUSE_PAGE: (c) => SellHousePage(),
  };
}